package week3.day15;

import java.util.Objects;

/**
 * @Author fengzihao
 * @Date 2024-04-29 19:47
 */
public class Animal {
    int age;
    String name;
    double price;

    // @Override
    // public boolean equals(Object o) {
    //     if (this == o) return true;
    //     if (o == null || getClass() != o.getClass()) return false;
    //     Animal animal = (Animal) o;
    //     return age == animal.age && Double.compare(price, animal.price) == 0 && Objects.equals(name, animal.name);
    // }
    //
    // @Override
    // public int hashCode() {
    //     return Objects.hash(age, name, price);
    // }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Animal animal)) return false;
        return age == animal.age && Double.compare(price, animal.price) == 0 && Objects.equals(name, animal.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name, price);
    }
}
